package com.ms.content.util;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.ms.common.entiey.ALipayBean;

public class AliPayUtil {
    public static String connect(ALipayBean alipayBean) throws AlipayApiException {
//1、获得初始化的AlipayClient
        AlipayClient alipayClient = new DefaultAlipayClient(
//支付宝网关
                "https://openapi.alipay.com/gateway.do",
//appid
                "2018050502638388",
//商户私钥
                "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDYjdzCwbdC9rlBcf6Sx9VuXz2njtebsMKkTxicfwlGJdnmMXLHuwxaB1Bw+myDy7e+S2wghWMXwGvjVd7VxDiMGdznSIHnp4sAhe18qazNc8yWLQb33vxwZupxXBlWvqZF6LoeXMgVKxwxIDrEgHPO7KJ9z7DtImu/3gLBC/QpusWHJyco9p4hN4fIOW/Hr6xKbS9avEFhhrmacLxloEKBTCQz9nPFb9C6E+OX0FWojbCiPcIrBUUKxrwHkvjibO4lmYhWiHdqjQ02loqc6gO5zDZSS9WQrEDjLdpRoQWGlXKTw4Nie1ID0ER130T+7UW9aGw2BMEkr649rcTHWb5HAgMBAAECggEAbry0fB8lQKf7+dx6KsLngGZRl+JynNnZ3r3XvwczTdzDPXRh1oLvAQameu+EGC1Pi47z/vlWv+mVAg6CQdvycqozDU5Fp5lEeoMB+3Kku/cQUmc6Hfy4KB5omolXJ8WcLzmgGzCk3DZMV0683ok1L0ZQnXdcaRbl9Jpp3B/pvoAjqYqxP7b+I2HrzsRBb5wHpa8cdc9KmanggQHCrKLDqdpvWHXqRZIh7in3GxsO7Q1J7DrMa2Rqof1YlawKNuy/pHclX9Njiv47iGE50fA7kPQYlzFbG8OgE4urQYhQRvpj3HtWJc7kAONksmoXEhDCd6VjyrjTIQHmQPKSwmINEQKBgQD4G2kLvdaoi2RRzK72710JHiasseW5wQJ13nwXpzzG+SRliJoR2f8jYFqsqeyjLZnj3LsfwYkTqA5bTmHFzBQttqXdpivTKj5JCDyS4N8cUfThSyzRCiDubDArwWiB6KEsdfaKUi/wHF09LKq8wWjeLMm6CCWAWMtPL2rZoMzeuQKBgQDfcXv6uJ5vvhTJ6yHZYL21eFozwjlGFhMWIZxytNQ+n24U4721+T+Aj9CYTvhUVLXy0QoWuh08Bf4fogDqV8/MaNHIOn0sLG7kJwr9BPRtOJ7YtCYM/QwhFgxtJJXYxb1f95juslggHNGboik1LqFjy77aJQlxiJAwf4vo57UE/wKBgQCYkOJrofUZ931c/6ynlFF1heDqWQqWyyUkLgfI08H/6LyE4xc62v6VVm7rtiIZxbTX9afrwyrzt2f8pZph8ziFU8dzIPfaBiP+7N2yxCzuUUdwMrYAZWYSttx4S5pkKBTULkXIkPmBgS+kqo7jO1utI4V4rAHDhtaeft4JrWPNoQKBgQCaZ+ms0Hdr8IadIgc6GEgAZzKuIcFCVW7LFF7wRVWGENYZSWeHoL3pMXiMR8YDQKabLSkzm1koaVu6sFDBn/zQ3H5bR0/IfswCjZhiUFI4R7A9QAAraZJAKuRbZ7TFH6BF+OuNx2BukHuoeN7RCXAtblZsmLt14VECsqEUSUomMQKBgEXxmuJdFwOtqsbxfTIw23iB8ajdXh0WfY3LDKPziol/vjud5gc1MzJIgolgVjStFqsf1UzSYofmXFVVUCUS6QotcaLbfb4Uwla8MPJbirtqEx98Taoo3NI8vDwxCZpE3BJbmaeR0J0BRE/GLEr+odnIERoJTlu1PMitkkjOUHsV",

                "json",
//字符编码格式
                "utf-8",
//支付宝公钥
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsl4UFld+tHTX/NV7mD489aWekpJchEVIdbdCncyWT+AjZryxonkqlv7o+1hkPW7xJPXX4VHbAh7ICkPRl5Ol1h4DVlUo4Wy7R+eIzDAQXDrmiF/aDyT9eGtorOxUnVQefT5hMTqUcLFq4nawn26fg9MLc+zsLkjmNbaqPHAbAEfApPTfZlfhy0juVD2hkiC9qeoRy2S7mKU71LOkXmu0zdVX94DOIlqDJVcnvM3t3Oi42w0rQBw+bL4z/TYtf7i05XPBeVTWDYn55GoRdsdEyQ/RTkXkgRbnhRqHCEGZ44C/LDCH8obXrw0pRgElVRWfdqpdfE1bOQ2hKj9MDJieawIDAQAB",
//签名方式
                "RSA2"
        );
//2、设置请求参数
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
//页面跳转同步通知页面路径
        alipayRequest.setReturnUrl("http://工程公网访问地址/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp");
// 服务器异步通知页面路径
        alipayRequest.setNotifyUrl("http://工程公网访问地址/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp");
//封装参数
        alipayRequest.setBizContent(JSON.toJSONString(alipayBean));
//3、请求支付宝进行付款，并获取支付结果
        String result = alipayClient.pageExecute(alipayRequest).getBody();
//返回付款信息
        return result;
    }
}
